package models.ticket;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import models.User;

import play.db.ebean.Model;

/*
 * Ticket message model encapsulates the messages
 * Author: Erasyl Dabyssov
 */

@Entity
public class TicketMessage extends Model {

	@Id
	public Long id;
	
	@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	public User user;
	public String message;
	
	@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	public Ticket ticket;
	
	public static Finder<Long, TicketMessage> find = new Finder<Long, TicketMessage>(Long.class, TicketMessage.class);
	
	public static TicketMessage create(User user, String message)
	{
		TicketMessage ticketMessage = new TicketMessage();
		ticketMessage.user = user;
		ticketMessage.message = message;
		
		return ticketMessage;
	}
}
